package com.aaa.mbs.controller;

import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import com.aaa.mbs.entity.IntegrationHistory;
import com.aaa.mbs.service.IntegrationHistoryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (IntegrationHistory)表控制层
 *
 * @author yuxiujie
 * @since 2021-01-23 10:19:57
 */
@RestController
@RequestMapping("integrationHistory")
@ApiOperation("integrationHistory控制器")
public class IntegrationHistoryController {
    /**
     * 服务对象
     */
    @Resource
    private IntegrationHistoryService integrationHistoryService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("单个对象查询")
    public Result<IntegrationHistory> selectOne(Long id) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.integrationHistoryService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public Result<PageInfo<IntegrationHistory>> queryAll(Integer pageNo, Integer pageSize, @RequestBody IntegrationHistory integrationHistory) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.integrationHistoryService.queryAll(pageNo, pageSize, integrationHistory));
    }

    /**
     * 新增数据
     *
     * @param integrationHistory 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result<IntegrationHistory> insert(@RequestBody IntegrationHistory integrationHistory) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.integrationHistoryService.insert(integrationHistory));
    }

    /**
     * 修改数据
     *
     * @param integrationHistory 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result<IntegrationHistory> update(@RequestBody IntegrationHistory integrationHistory) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.integrationHistoryService.update(integrationHistory));
    }

    /**
     * 通过主键删除数据
     *
     * @param integrationHistoryId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById/{integrationHistoryId}")
    public Result<Boolean> deleteById(@PathVariable("integrationHistoryId") Long integrationHistoryId) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.integrationHistoryService.deleteById(integrationHistoryId));
    }
}